        <!DOCTYPE html>
        <html>
        <head>
                <meta charset="utf-8">
        <title>Simplex class / box2d_console Library / Dart Documentation</title>
        <link rel="stylesheet" type="text/css"
            href="../styles.css">
        <link href="http://fonts.googleapis.com/css?family=Open+Sans:400,600,700,800" rel="stylesheet" type="text/css">
        <link rel="shortcut icon" href="../favicon.ico">
        
        </head>
        <body data-library="box2d_console" data-type="Simplex">
        <div class="page">
        <div class="header">
          <a href="../index.html"><div class="logo"></div></a>
          <a href="../index.html">Dart Documentation</a>
         &rsaquo; <a href="../box2d_console.html">box2d_console</a> &rsaquo; <a href="../box2d_console/Simplex.html">Simplex</a>        <div id="search-box">
          <input type="search" name="q" id="q" autocomplete="off"
              class="search-input" placeholder="Search API">
        </div>
        
      </div>
      <div class="drop-down" id="drop-down"></div>
      
        <div class="nav">
        
</div>
<div class="content">
        <h2><strong>Simplex</strong>
          class
        </h2>
        
<button id="show-inherited" class="show-inherited">Hide inherited</button>
<div class="doc">
<p>Class for internal use by Distance.dart.</p>
<pre class="source">
class Simplex {
  final SimplexVertex v1;
  final SimplexVertex v2;
  final SimplexVertex v3;
  final List&lt;SimplexVertex&gt; vertices;
  int count;

  Simplex() :
    count = 0,
    v1 = new SimplexVertex(),
    v2 = new SimplexVertex(),
    v3 = new SimplexVertex(),
    vertices = new List&lt;SimplexVertex&gt;(3),
    e13 = new Vector(),
    e12 = new Vector(),
    e23 = new Vector(),
    case2 = new Vector(),
    case22 = new Vector(),
    case3 = new Vector(),
    case33 = new Vector() {

    vertices[0] = v1;
    vertices[1] = v2;
    vertices[2] = v3;
  }

  /** Pooling. */
  final Vector e13;
  final Vector e23;
  final Vector e12;
  final Vector case2;
  final Vector case22;
  final Vector case3;
  final Vector case33;

  void readCache(SimplexCache cache, DistanceProxy proxyA,
      Transform transformA, DistanceProxy proxyB,
      Transform transformB) {
    assert (cache.count &lt;= 3);

    // Copy data from cache.
    count = cache.count;

    for (int i = 0; i &lt; count; ++i) {
      SimplexVertex v = vertices[i];
      v.indexA = cache.indexA[i];
      v.indexB = cache.indexB[i];
      Vector wALocal = proxyA.vertices[v.indexA];
      Vector wBLocal = proxyB.vertices[v.indexB];
      Transform.mulToOut(transformA, wALocal, v.wA);
      Transform.mulToOut(transformB, wBLocal, v.wB);
      v.w.setFrom(v.wB).subLocal(v.wA);
      v.a = 0.0;
    }

    // Compute the new simplex metric, if it is substantially different than
    // old metric then flush the simplex.
    if (count &gt; 1) {
      num metric1 = cache.metric;
      num metric2 = getMetric();
      if (metric2 &lt; 0.5 * metric1 || 2.0 * metric1 &lt; metric2 || metric2 &lt;
          Settings.EPSILON) {
        // Reset the simplex.
        count = 0;
      }
    }

    // If the cache is empty or invalid ...
    if (count == 0) {
      SimplexVertex v = vertices[0];
      v.indexA = 0;
      v.indexB = 0;
      Vector wALocal = proxyA.vertices[0];
      Vector wBLocal = proxyB.vertices[0];
      Transform.mulToOut(transformA, wALocal, v.wA);
      Transform.mulToOut(transformB, wBLocal, v.wB);
      v.w.setFrom(v.wB).subLocal(v.wA);
      count = 1;
    }
  }

  void writeCache(SimplexCache cache) {
    cache.metric = getMetric();
    cache.count = count;

    for (int i = 0; i &lt; count; ++i) {
      cache.indexA[i] = (vertices[i].indexA);
      cache.indexB[i] = (vertices[i].indexB);
    }
  }

  void getSearchDirection(Vector out) {
    switch (count) {
      case 1 :
        out.setFrom(v1.w).negateLocal();
        return;
      case 2 :
        e12.setFrom(v2.w).subLocal(v1.w);
        // use out for a temp variable real quick
        out.setFrom(v1.w).negateLocal();
        num sgn = Vector.crossVectors(e12, out);

        if (sgn &gt; 0) {
          // Origin is left of e12.
          Vector.crossNumAndVectorToOut(1, e12, out);
        }
        else {
          // Origin is right of e12.
          Vector.crossVectorAndNumToOut(e12, 1, out);
        }
        break;
      default :
        assert (false);
        out.setZero();
        return;
    }
  }


  /**
   * this returns pooled objects. don't keep or modify them
   */
  void getClosestPoint(Vector out) {
    switch (count) {
      case 0 :
        assert (false);
        out.setZero();
        return;
      case 1 :
        out.setFrom(v1.w);
        return;
      case 2 :
        case22.setFrom(v2.w).mulLocal(v2.a);
        case2.setFrom(v1.w).mulLocal(v1.a).addLocal(case22);
        out.setFrom(case2);
        return;
      case 3 :
        out.setZero();
        return;
      default :
        assert (false);
        out.setZero();
        return;
    }
  }


  void getWitnessPoints(Vector pA, Vector pB) {
    switch (count) {
      case 0 :
        assert (false);
        break;

      case 1 :
        pA.setFrom(v1.wA);
        pB.setFrom(v1.wB);
        break;

      case 2 :
        case2.setFrom(v1.wA).mulLocal(v1.a);
        pA.setFrom(v2.wA).mulLocal(v2.a).addLocal(case2);
        case2.setFrom(v1.wB).mulLocal(v1.a);
        pB.setFrom(v2.wB).mulLocal(v2.a).addLocal(case2);

        break;

      case 3 :
        pA.setFrom(v1.wA).mulLocal(v1.a);
        case3.setFrom(v2.wA).mulLocal(v2.a);
        case33.setFrom(v3.wA).mulLocal(v3.a);
        pA.addLocal(case3).addLocal(case33);
        pB.setFrom(pA);
        break;

      default :
        assert (false);
        break;
    }
  }

  num getMetric() {
    switch (count) {
      case 0 :
        assert (false);
        return 0.0;

      case 1 :
        return 0.0;

      case 2 :
        return MathBox.distance(v1.w, v2.w);

      case 3 :
        case3.setFrom(v2.w).subLocal(v1.w);
        case33.setFrom(v3.w).subLocal(v1.w);
        return Vector.crossVectors(case3, case33);

      default :
        assert (false);
        return 0.0;
    }
  }

  /**
   * Solve a line segment using barycentric coordinates.
   */
  void solve2() {
    Vector w1 = v1.w;
    Vector w2 = v2.w;
    e12.setFrom(w2).subLocal(w1);

    // w1 region
    num d12_2 = -Vector.dot(w1, e12);
    if (d12_2 &lt;= 0.0) {
      // a2 &lt;= 0, so we clamp it to 0
      v1.a = 1.0;
      count = 1;
      return;
    }

    // w2 region
    num d12_1 = Vector.dot(w2, e12);
    if (d12_1 &lt;= 0.0) {
      // a1 &lt;= 0, so we clamp it to 0
      v2.a = 1.0;
      count = 1;
      v1.setFrom(v2);
      return;
    }

    // Must be in e12 region.
    num inv_d12 = 1.0 / (d12_1 + d12_2);
    v1.a = d12_1 * inv_d12;
    v2.a = d12_2 * inv_d12;
    count = 2;
  }

  /**
   * Solve a line segment using barycentric coordinates.&lt;br/&gt;
   * Possible regions:&lt;br/&gt;
   * - points[2]&lt;br/&gt;
   * - edge points[0]-points[2]&lt;br/&gt;
   * - edge points[1]-points[2]&lt;br/&gt;
   * - inside the triangle
   */
  void solve3() {
    Vector w1 = v1.w;
    Vector w2 = v2.w;
    Vector w3 = v3.w;

    // Edge12
    e12.setFrom(w2).subLocal(w1);
    num w1e12 = Vector.dot(w1, e12);
    num w2e12 = Vector.dot(w2, e12);
    num d12_1 = w2e12;
    num d12_2 = -w1e12;

    // Edge13
    e13.setFrom(w3).subLocal(w1);
    num w1e13 = Vector.dot(w1, e13);
    num w3e13 = Vector.dot(w3, e13);
    num d13_1 = w3e13;
    num d13_2 = -w1e13;

    // Edge23
    e23.setFrom(w3).subLocal(w2);
    num w2e23 = Vector.dot(w2, e23);
    num w3e23 = Vector.dot(w3, e23);
    num d23_1 = w3e23;
    num d23_2 = -w2e23;

    // Triangle123
    num n123 = Vector.crossVectors(e12, e13);

    num d123_1 = n123 * Vector.crossVectors(w2, w3);
    num d123_2 = n123 * Vector.crossVectors(w3, w1);
    num d123_3 = n123 * Vector.crossVectors(w1, w2);

    // w1 region
    if (d12_2 &lt;= 0.0 &amp;&amp; d13_2 &lt;= 0.0) {
      v1.a = 1.0;
      count = 1;
      return;
    }

    // e12
    if (d12_1 &gt; 0.0 &amp;&amp; d12_2 &gt; 0.0 &amp;&amp; d123_3 &lt;= 0.0) {
      num inv_d12 = 1.0 / (d12_1 + d12_2);
      v1.a = d12_1 * inv_d12;
      v2.a = d12_2 * inv_d12;
      count = 2;
      return;
    }

    // e13
    if (d13_1 &gt; 0.0 &amp;&amp; d13_2 &gt; 0.0 &amp;&amp; d123_2 &lt;= 0.0) {
      num inv_d13 = 1.0 / (d13_1 + d13_2);
      v1.a = d13_1 * inv_d13;
      v3.a = d13_2 * inv_d13;
      count = 2;
      v2.setFrom(v3);
      return;
    }

    // w2 region
    if (d12_1 &lt;= 0.0 &amp;&amp; d23_2 &lt;= 0.0) {
      v2.a = 1.0;
      count = 1;
      v1.setFrom(v2);
      return;
    }

    // w3 region
    if (d13_1 &lt;= 0.0 &amp;&amp; d23_1 &lt;= 0.0) {
      v3.a = 1.0;
      count = 1;
      v1.setFrom(v3);
      return;
    }

    // e23
    if (d23_1 &gt; 0.0 &amp;&amp; d23_2 &gt; 0.0 &amp;&amp; d123_1 &lt;= 0.0) {
      num inv_d23 = 1.0 / (d23_1 + d23_2);
      v2.a = d23_1 * inv_d23;
      v3.a = d23_2 * inv_d23;
      count = 2;
      v1.setFrom(v3);
      return;
    }

    // Must be in triangle123
    num inv_d123 = 1.0 / (d123_1 + d123_2 + d123_3);
    v1.a = d123_1 * inv_d123;
    v2.a = d123_2 * inv_d123;
    v3.a = d123_3 * inv_d123;
    count = 3;
  }
}
</pre>
</div>
<div>
<h3>Constructors</h3>
<div class="method"><h4 id="Simplex">
<button class="show-code">Code</button>
new <strong>Simplex</strong>() <a class="anchor-link" href="#Simplex"
              title="Permalink to Simplex.Simplex">#</a></h4>
<div class="doc">
<pre class="source">
Simplex() :
  count = 0,
  v1 = new SimplexVertex(),
  v2 = new SimplexVertex(),
  v3 = new SimplexVertex(),
  vertices = new List&lt;SimplexVertex&gt;(3),
  e13 = new Vector(),
  e12 = new Vector(),
  e23 = new Vector(),
  case2 = new Vector(),
  case22 = new Vector(),
  case3 = new Vector(),
  case33 = new Vector() {

  vertices[0] = v1;
  vertices[1] = v2;
  vertices[2] = v3;
}
</pre>
</div>
</div>
</div>
<div>
<h3>Properties</h3>
<div class="field"><h4 id="case2">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>case2</strong> <a class="anchor-link"
            href="#case2"
            title="Permalink to Simplex.case2">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Vector case2;
</pre>
</div>
</div>
<div class="field"><h4 id="case22">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>case22</strong> <a class="anchor-link"
            href="#case22"
            title="Permalink to Simplex.case22">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Vector case22;
</pre>
</div>
</div>
<div class="field"><h4 id="case3">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>case3</strong> <a class="anchor-link"
            href="#case3"
            title="Permalink to Simplex.case3">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Vector case3;
</pre>
</div>
</div>
<div class="field"><h4 id="case33">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>case33</strong> <a class="anchor-link"
            href="#case33"
            title="Permalink to Simplex.case33">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Vector case33;
</pre>
</div>
</div>
<div class="field"><h4 id="count">
<button class="show-code">Code</button>
int         <strong>count</strong> <a class="anchor-link"
            href="#count"
            title="Permalink to Simplex.count">#</a>
        </h4>
        <div class="doc">
<pre class="source">
int count;
</pre>
</div>
</div>
<div class="field"><h4 id="e12">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>e12</strong> <a class="anchor-link"
            href="#e12"
            title="Permalink to Simplex.e12">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Vector e12;
</pre>
</div>
</div>
<div class="field"><h4 id="e13">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>e13</strong> <a class="anchor-link"
            href="#e13"
            title="Permalink to Simplex.e13">#</a>
        </h4>
        <div class="doc">
<p>Pooling.</p>
<pre class="source">
final Vector e13;
</pre>
</div>
</div>
<div class="field"><h4 id="e23">
<button class="show-code">Code</button>
final <a href="../box2d_console/Vector.html">Vector</a>         <strong>e23</strong> <a class="anchor-link"
            href="#e23"
            title="Permalink to Simplex.e23">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final Vector e23;
</pre>
</div>
</div>
<div class="field inherited"><h4 id="runtimeType">
<button class="show-code">Code</button>
final Type         <strong>runtimeType</strong> <a class="anchor-link"
            href="#runtimeType"
            title="Permalink to Simplex.runtimeType">#</a>
        </h4>
        <div class="inherited-from">inherited from Object </div><div class="doc">
<p>A representation of the runtime type of the object.</p>
<pre class="source">
external Type get runtimeType;
</pre>
</div>
</div>
<div class="field"><h4 id="v1">
<button class="show-code">Code</button>
final <a href="../box2d_console/SimplexVertex.html">SimplexVertex</a>         <strong>v1</strong> <a class="anchor-link"
            href="#v1"
            title="Permalink to Simplex.v1">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final SimplexVertex v1;
</pre>
</div>
</div>
<div class="field"><h4 id="v2">
<button class="show-code">Code</button>
final <a href="../box2d_console/SimplexVertex.html">SimplexVertex</a>         <strong>v2</strong> <a class="anchor-link"
            href="#v2"
            title="Permalink to Simplex.v2">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final SimplexVertex v2;
</pre>
</div>
</div>
<div class="field"><h4 id="v3">
<button class="show-code">Code</button>
final <a href="../box2d_console/SimplexVertex.html">SimplexVertex</a>         <strong>v3</strong> <a class="anchor-link"
            href="#v3"
            title="Permalink to Simplex.v3">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final SimplexVertex v3;
</pre>
</div>
</div>
<div class="field"><h4 id="vertices">
<button class="show-code">Code</button>
final List&lt;<a href="../box2d_console/SimplexVertex.html">SimplexVertex</a>&gt;         <strong>vertices</strong> <a class="anchor-link"
            href="#vertices"
            title="Permalink to Simplex.vertices">#</a>
        </h4>
        <div class="doc">
<pre class="source">
final List&lt;SimplexVertex&gt; vertices;
</pre>
</div>
</div>
</div>
<div>
<h3>Operators</h3>
<div class="method inherited"><h4 id="==">
<button class="show-code">Code</button>
bool <strong>operator ==</strong>(other) <a class="anchor-link" href="#=="
              title="Permalink to Simplex.operator ==">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>The equality operator.</p>
<p>The default behavior for all <code>Object</code>s is to return true if and
only if <code>this</code> and 
<span class="param">other</span> are the same object.</p>
<p>If a subclass overrides the equality operator it should override
the <code>hashCode</code> method as well to maintain consistency.</p>
<pre class="source">
bool operator ==(other) =&gt; identical(this, other);
</pre>
</div>
</div>
</div>
<div>
<h3>Methods</h3>
<div class="method"><h4 id="getClosestPoint">
<button class="show-code">Code</button>
void <strong>getClosestPoint</strong>(<a href="../box2d_console/Vector.html">Vector</a> out) <a class="anchor-link" href="#getClosestPoint"
              title="Permalink to Simplex.getClosestPoint">#</a></h4>
<div class="doc">
<p>this returns pooled objects. don't keep or modify them</p>
<pre class="source">
void getClosestPoint(Vector out) {
  switch (count) {
    case 0 :
      assert (false);
      out.setZero();
      return;
    case 1 :
      out.setFrom(v1.w);
      return;
    case 2 :
      case22.setFrom(v2.w).mulLocal(v2.a);
      case2.setFrom(v1.w).mulLocal(v1.a).addLocal(case22);
      out.setFrom(case2);
      return;
    case 3 :
      out.setZero();
      return;
    default :
      assert (false);
      out.setZero();
      return;
  }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getMetric">
<button class="show-code">Code</button>
num <strong>getMetric</strong>() <a class="anchor-link" href="#getMetric"
              title="Permalink to Simplex.getMetric">#</a></h4>
<div class="doc">
<pre class="source">
num getMetric() {
  switch (count) {
    case 0 :
      assert (false);
      return 0.0;

    case 1 :
      return 0.0;

    case 2 :
      return MathBox.distance(v1.w, v2.w);

    case 3 :
      case3.setFrom(v2.w).subLocal(v1.w);
      case33.setFrom(v3.w).subLocal(v1.w);
      return Vector.crossVectors(case3, case33);

    default :
      assert (false);
      return 0.0;
  }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getSearchDirection">
<button class="show-code">Code</button>
void <strong>getSearchDirection</strong>(<a href="../box2d_console/Vector.html">Vector</a> out) <a class="anchor-link" href="#getSearchDirection"
              title="Permalink to Simplex.getSearchDirection">#</a></h4>
<div class="doc">
<pre class="source">
void getSearchDirection(Vector out) {
  switch (count) {
    case 1 :
      out.setFrom(v1.w).negateLocal();
      return;
    case 2 :
      e12.setFrom(v2.w).subLocal(v1.w);
      // use out for a temp variable real quick
      out.setFrom(v1.w).negateLocal();
      num sgn = Vector.crossVectors(e12, out);

      if (sgn &gt; 0) {
        // Origin is left of e12.
        Vector.crossNumAndVectorToOut(1, e12, out);
      }
      else {
        // Origin is right of e12.
        Vector.crossVectorAndNumToOut(e12, 1, out);
      }
      break;
    default :
      assert (false);
      out.setZero();
      return;
  }
}
</pre>
</div>
</div>
<div class="method"><h4 id="getWitnessPoints">
<button class="show-code">Code</button>
void <strong>getWitnessPoints</strong>(<a href="../box2d_console/Vector.html">Vector</a> pA, <a href="../box2d_console/Vector.html">Vector</a> pB) <a class="anchor-link" href="#getWitnessPoints"
              title="Permalink to Simplex.getWitnessPoints">#</a></h4>
<div class="doc">
<pre class="source">
void getWitnessPoints(Vector pA, Vector pB) {
  switch (count) {
    case 0 :
      assert (false);
      break;

    case 1 :
      pA.setFrom(v1.wA);
      pB.setFrom(v1.wB);
      break;

    case 2 :
      case2.setFrom(v1.wA).mulLocal(v1.a);
      pA.setFrom(v2.wA).mulLocal(v2.a).addLocal(case2);
      case2.setFrom(v1.wB).mulLocal(v1.a);
      pB.setFrom(v2.wB).mulLocal(v2.a).addLocal(case2);

      break;

    case 3 :
      pA.setFrom(v1.wA).mulLocal(v1.a);
      case3.setFrom(v2.wA).mulLocal(v2.a);
      case33.setFrom(v3.wA).mulLocal(v3.a);
      pA.addLocal(case3).addLocal(case33);
      pB.setFrom(pA);
      break;

    default :
      assert (false);
      break;
  }
}
</pre>
</div>
</div>
<div class="method inherited"><h4 id="hashCode">
<button class="show-code">Code</button>
int <strong>hashCode</strong>() <a class="anchor-link" href="#hashCode"
              title="Permalink to Simplex.hashCode">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Get a hash code for this object.</p>
<p>All objects have hash codes. Hash codes are guaranteed to be the
same for objects that are equal when compared using the equality
operator <code>==</code>. Other than that there are no guarantees about
the hash codes. They will not be consistent between runs and
there are no distribution guarantees.</p>
<p>If a subclass overrides <code>hashCode</code> it should override the
equality operator as well to maintain consistency.</p>
<pre class="source">
external int hashCode();
</pre>
</div>
</div>
<div class="method inherited"><h4 id="noSuchMethod">
<button class="show-code">Code</button>
<strong>noSuchMethod</strong>(String name, List args) <a class="anchor-link" href="#noSuchMethod"
              title="Permalink to Simplex.noSuchMethod">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p><code>noSuchMethod</code> is invoked when users invoke a non-existant method
on an object. The name of the method and the arguments of the
invocation are passed to <code>noSuchMethod</code>. If <code>noSuchMethod</code>
returns a value, that value becomes the result of the original
invocation.</p>
<p>The default behavior of <code>noSuchMethod</code> is to throw a
<code>noSuchMethodError</code>.</p>
<pre class="source">
external Dynamic noSuchMethod(String name, List args);
</pre>
</div>
</div>
<div class="method inherited"><h4 id="Object">
<button class="show-code">Code</button>
const <strong>Object</strong>() <a class="anchor-link" href="#Object"
              title="Permalink to Simplex.Object">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Creates a new <code>Object</code> instance.</p>
<p><code>Object</code> instances have no meaningful state, and are only useful
through their identity. An <code>Object</code> instance is equal to itself
only.</p>
<pre class="source">
const Object();
</pre>
</div>
</div>
<div class="method"><h4 id="readCache">
<button class="show-code">Code</button>
void <strong>readCache</strong>(<a href="../box2d_console/SimplexCache.html">SimplexCache</a> cache, <a href="../box2d_console/DistanceProxy.html">DistanceProxy</a> proxyA, <a href="../box2d_console/Transform.html">Transform</a> transformA, <a href="../box2d_console/DistanceProxy.html">DistanceProxy</a> proxyB, <a href="../box2d_console/Transform.html">Transform</a> transformB) <a class="anchor-link" href="#readCache"
              title="Permalink to Simplex.readCache">#</a></h4>
<div class="doc">
<pre class="source">
void readCache(SimplexCache cache, DistanceProxy proxyA,
    Transform transformA, DistanceProxy proxyB,
    Transform transformB) {
  assert (cache.count &lt;= 3);

  // Copy data from cache.
  count = cache.count;

  for (int i = 0; i &lt; count; ++i) {
    SimplexVertex v = vertices[i];
    v.indexA = cache.indexA[i];
    v.indexB = cache.indexB[i];
    Vector wALocal = proxyA.vertices[v.indexA];
    Vector wBLocal = proxyB.vertices[v.indexB];
    Transform.mulToOut(transformA, wALocal, v.wA);
    Transform.mulToOut(transformB, wBLocal, v.wB);
    v.w.setFrom(v.wB).subLocal(v.wA);
    v.a = 0.0;
  }

  // Compute the new simplex metric, if it is substantially different than
  // old metric then flush the simplex.
  if (count &gt; 1) {
    num metric1 = cache.metric;
    num metric2 = getMetric();
    if (metric2 &lt; 0.5 * metric1 || 2.0 * metric1 &lt; metric2 || metric2 &lt;
        Settings.EPSILON) {
      // Reset the simplex.
      count = 0;
    }
  }

  // If the cache is empty or invalid ...
  if (count == 0) {
    SimplexVertex v = vertices[0];
    v.indexA = 0;
    v.indexB = 0;
    Vector wALocal = proxyA.vertices[0];
    Vector wBLocal = proxyB.vertices[0];
    Transform.mulToOut(transformA, wALocal, v.wA);
    Transform.mulToOut(transformB, wBLocal, v.wB);
    v.w.setFrom(v.wB).subLocal(v.wA);
    count = 1;
  }
}
</pre>
</div>
</div>
<div class="method"><h4 id="Simplex">
<button class="show-code">Code</button>
new <strong>Simplex</strong>() <a class="anchor-link" href="#Simplex"
              title="Permalink to Simplex.Simplex">#</a></h4>
<div class="doc">
<pre class="source">
Simplex() :
  count = 0,
  v1 = new SimplexVertex(),
  v2 = new SimplexVertex(),
  v3 = new SimplexVertex(),
  vertices = new List&lt;SimplexVertex&gt;(3),
  e13 = new Vector(),
  e12 = new Vector(),
  e23 = new Vector(),
  case2 = new Vector(),
  case22 = new Vector(),
  case3 = new Vector(),
  case33 = new Vector() {

  vertices[0] = v1;
  vertices[1] = v2;
  vertices[2] = v3;
}
</pre>
</div>
</div>
<div class="method"><h4 id="solve2">
<button class="show-code">Code</button>
void <strong>solve2</strong>() <a class="anchor-link" href="#solve2"
              title="Permalink to Simplex.solve2">#</a></h4>
<div class="doc">
<p>Solve a line segment using barycentric coordinates.</p>
<pre class="source">
void solve2() {
  Vector w1 = v1.w;
  Vector w2 = v2.w;
  e12.setFrom(w2).subLocal(w1);

  // w1 region
  num d12_2 = -Vector.dot(w1, e12);
  if (d12_2 &lt;= 0.0) {
    // a2 &lt;= 0, so we clamp it to 0
    v1.a = 1.0;
    count = 1;
    return;
  }

  // w2 region
  num d12_1 = Vector.dot(w2, e12);
  if (d12_1 &lt;= 0.0) {
    // a1 &lt;= 0, so we clamp it to 0
    v2.a = 1.0;
    count = 1;
    v1.setFrom(v2);
    return;
  }

  // Must be in e12 region.
  num inv_d12 = 1.0 / (d12_1 + d12_2);
  v1.a = d12_1 * inv_d12;
  v2.a = d12_2 * inv_d12;
  count = 2;
}
</pre>
</div>
</div>
<div class="method"><h4 id="solve3">
<button class="show-code">Code</button>
void <strong>solve3</strong>() <a class="anchor-link" href="#solve3"
              title="Permalink to Simplex.solve3">#</a></h4>
<div class="doc">
<p>Solve a line segment using barycentric coordinates.&lt;br/>
Possible regions:&lt;br/>
- points<code>2</code>&lt;br/>
- edge points<code>0</code>-points<code>2</code>&lt;br/>
- edge points<code>1</code>-points<code>2</code>&lt;br/>
- inside the triangle</p>
<pre class="source">
void solve3() {
  Vector w1 = v1.w;
  Vector w2 = v2.w;
  Vector w3 = v3.w;

  // Edge12
  e12.setFrom(w2).subLocal(w1);
  num w1e12 = Vector.dot(w1, e12);
  num w2e12 = Vector.dot(w2, e12);
  num d12_1 = w2e12;
  num d12_2 = -w1e12;

  // Edge13
  e13.setFrom(w3).subLocal(w1);
  num w1e13 = Vector.dot(w1, e13);
  num w3e13 = Vector.dot(w3, e13);
  num d13_1 = w3e13;
  num d13_2 = -w1e13;

  // Edge23
  e23.setFrom(w3).subLocal(w2);
  num w2e23 = Vector.dot(w2, e23);
  num w3e23 = Vector.dot(w3, e23);
  num d23_1 = w3e23;
  num d23_2 = -w2e23;

  // Triangle123
  num n123 = Vector.crossVectors(e12, e13);

  num d123_1 = n123 * Vector.crossVectors(w2, w3);
  num d123_2 = n123 * Vector.crossVectors(w3, w1);
  num d123_3 = n123 * Vector.crossVectors(w1, w2);

  // w1 region
  if (d12_2 &lt;= 0.0 &amp;&amp; d13_2 &lt;= 0.0) {
    v1.a = 1.0;
    count = 1;
    return;
  }

  // e12
  if (d12_1 &gt; 0.0 &amp;&amp; d12_2 &gt; 0.0 &amp;&amp; d123_3 &lt;= 0.0) {
    num inv_d12 = 1.0 / (d12_1 + d12_2);
    v1.a = d12_1 * inv_d12;
    v2.a = d12_2 * inv_d12;
    count = 2;
    return;
  }

  // e13
  if (d13_1 &gt; 0.0 &amp;&amp; d13_2 &gt; 0.0 &amp;&amp; d123_2 &lt;= 0.0) {
    num inv_d13 = 1.0 / (d13_1 + d13_2);
    v1.a = d13_1 * inv_d13;
    v3.a = d13_2 * inv_d13;
    count = 2;
    v2.setFrom(v3);
    return;
  }

  // w2 region
  if (d12_1 &lt;= 0.0 &amp;&amp; d23_2 &lt;= 0.0) {
    v2.a = 1.0;
    count = 1;
    v1.setFrom(v2);
    return;
  }

  // w3 region
  if (d13_1 &lt;= 0.0 &amp;&amp; d23_1 &lt;= 0.0) {
    v3.a = 1.0;
    count = 1;
    v1.setFrom(v3);
    return;
  }

  // e23
  if (d23_1 &gt; 0.0 &amp;&amp; d23_2 &gt; 0.0 &amp;&amp; d123_1 &lt;= 0.0) {
    num inv_d23 = 1.0 / (d23_1 + d23_2);
    v2.a = d23_1 * inv_d23;
    v3.a = d23_2 * inv_d23;
    count = 2;
    v1.setFrom(v3);
    return;
  }

  // Must be in triangle123
  num inv_d123 = 1.0 / (d123_1 + d123_2 + d123_3);
  v1.a = d123_1 * inv_d123;
  v2.a = d123_2 * inv_d123;
  v3.a = d123_3 * inv_d123;
  count = 3;
}
</pre>
</div>
</div>
<div class="method inherited"><h4 id="toString">
<button class="show-code">Code</button>
String <strong>toString</strong>() <a class="anchor-link" href="#toString"
              title="Permalink to Simplex.toString">#</a></h4>
<div class="inherited-from">inherited from Object </div><div class="doc">
<p>Returns a string representation of this object.</p>
<pre class="source">
external String toString();
</pre>
</div>
</div>
<div class="method"><h4 id="writeCache">
<button class="show-code">Code</button>
void <strong>writeCache</strong>(<a href="../box2d_console/SimplexCache.html">SimplexCache</a> cache) <a class="anchor-link" href="#writeCache"
              title="Permalink to Simplex.writeCache">#</a></h4>
<div class="doc">
<pre class="source">
void writeCache(SimplexCache cache) {
  cache.metric = getMetric();
  cache.count = count;

  for (int i = 0; i &lt; count; ++i) {
    cache.indexA[i] = (vertices[i].indexA);
    cache.indexB[i] = (vertices[i].indexB);
  }
}
</pre>
</div>
</div>
</div>
        </div>
        <div class="clear"></div>
        </div>
        
        <div class="footer">
          
        </div>
        <script async src="../client-live-nav.js"></script>
        </body></html>
        
